package com.tanhq.mystock.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;

/**
 * @RestController = @Controller + @ResponseBody
 */
@RestController
@RequestMapping(path = "/index")
public class IndexController {

    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);


    /**
     * http://localhost:8080/index/hello
     * @return
     */
    @GetMapping(value = "/hello")
    public String hello(){
        return "hello world!";
    }

    /**
     * http://localhost:8080/index/jvm-info
     * @return
     */
    @GetMapping(value = "/jvm-info")
    public String info(){
        List<GarbageCollectorMXBean> list = ManagementFactory.getGarbageCollectorMXBeans();
        StringBuilder sb = new StringBuilder();
        for (GarbageCollectorMXBean bean : list) {
            sb.append(bean.getName() + "\n");
        }
        return sb.toString();
    }


    public static void main(String[] args) {
        System.out.println("444444");
    }







}
